<HEAD>
  <SCRIPT SRC="../ganja.js"></SCRIPT>
</HEAD>
<BODY><SCRIPT>
// In quaternion space H, we calculate the mandelbrot set and use the
// iteration count for colorisation.

Algebra(0,2,()=>{
  
  document.body.appendChild(this.graph((x,y)=>{
  // Calculate iteration count for mandelbrot.
    var n=40,                      // Iteration count. 
        z=0e12,                    // A complex number Z.
        c=x*1.75-1+y*1e12,         // position in the complex plane.
        axis=0.578*(1e1+1e2+1e12); // The 1,1,1 axis.
        
  // See if this c escapes ..      
    while (z < 4 && n--) z=z**2+c;
    
  // Smooth iteration count and angle added in.
    n += Math.log2(Math.log2(Math.max(4,z.Length)))-Math.atan2(y,x)*10;
    
  // Use the iteration count to rotate the color red in the hue plane  
    var red=1e1,                                  
        rot=Math.cos(n/20) + Math.sin(n/20)*axis;
        
  // Rotate red around the 1,1,1 axis and return the resulting color      
    return (rot*red*rot.Conjugate).slice(1);

  }));

});  
</SCRIPT></BODY>